package util;

import dao.BaseDao;
import entity.SaleDetails;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class CeShiUtil extends BaseDao {
    //列表指定订单下的订单明细信息
    public List getAppointSaleDeatils(String saleIdTemp) throws Exception {
        List saleDetailsList = new ArrayList();
        String sql = "select saleDetailsId,saleId,productId,saleNumber" +
                " from saledetails where saleId='" + saleIdTemp + "'";
        System.out.println(sql);
        Connection connection = getConnection();//获取数据库连接
        Statement statement = connection.createStatement();//创建statement对象
        ResultSet resultSet = statement.executeQuery(sql);//执行查询sql
        while(resultSet.next()){
            String saleDetailsId = resultSet.getString("saleDetailsId");
            String saleId = resultSet.getString("saleId");
            String productId = resultSet.getString("productId");
            int saleNumber = resultSet.getInt("saleNumber");

            SaleDetails saleDetails = new SaleDetails(saleDetailsId,saleId,productId,saleNumber);
            saleDetailsList.add(saleDetails);
        }
        return saleDetailsList;
    }

    public static void main(String[] args) throws Exception {
        CeShiUtil ceshi = new CeShiUtil();
        List aaa = ceshi.getAppointSaleDeatils("XS202306081431137420650");
        System.out.println(aaa);
    }
}
